package cn.tedu.io.file;

import java.io.FileWriter;
import java.io.IOException;
//容灾
public class FileWriterDemo2 {
    public static void main(String[] args) {
        //1.声明流对象并且赋值为null
        FileWriter writer=null;
        try {
            //真正进行初始化
            writer=new FileWriter("D:\\2.txt");
            //写出数据
            writer.write("啦啦啦德玛西亚！！！");
            //4.手动冲刷
            writer.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            //2.保证流对象初始化成功之后才能关流
            if(writer!=null)
            try {
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
                //3.回收流对象
                writer=null;
            }
        }
    }
}
